package org.pathlet.core;

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import org.pathlet.core.impl.ClassNamePathConverter;



public class PathConverterTester {

    @Test
    public void testClassNamePathConverter() {

            ClassNamePathConverter converter = new ClassNamePathConverter();
            converter.setAppendPackage("impl");
            converter.setNamePrefix("Sys");
            converter.setNameSuffix("Impl");

            //properties: { appendPackage: "service.impl", namePrefix: "Sys", nameSuffix: "Impl"}

            Path basePath = new Path("/console");
            String basePackage = "com.uh";

            String className = converter.convertToType(new Path("/console/system/service/ConfigService"), basePath, basePackage);
            assertEquals("com.uh.system.service.impl.SysConfigServiceImpl", className); //



            Path path = converter.converToPath(className, basePath, basePackage);
            assertEquals("/console/system/service/ConfigService", path.toString());


            Path pathAgain = converter.converToPath("com.uh.system.service.SysConfigService", basePath, basePackage);
            assertEquals("/console/system/service/ConfigService", pathAgain.toString());

    }

    @Test
    public void testClassNamePathConverter2() {

        ClassNamePathConverter converter = new ClassNamePathConverter();
        converter.setAppendPackage("impl");
        //converter.setNamePrefix("Sys");
        converter.setNameSuffix("Impl");

        //properties: { appendPackage: "service.impl", namePrefix: "Sys", nameSuffix: "Impl"}

        Path basePath = new Path("/console");
        String basePackage = "com.uh";

        String className = converter.convertToType(new Path("/console/system/service/SysConfigService"), basePath, basePackage);
        assertEquals("com.uh.system.service.impl.SysConfigServiceImpl", className); //

        Path path = converter.converToPath(className, basePath, basePackage);
        assertEquals("/console/system/service/SysConfigService", path.toString());

        Path pathAgain = converter.converToPath("com.uh.system.service.SysConfigService", basePath, basePackage);
        assertEquals("/console/system/service/SysConfigService", pathAgain.toString());

    }


    @Test
    public void testClassNamePathConverter3() {

        ClassNamePathConverter converter = new ClassNamePathConverter();
        //converter.setAppendPackage("impl");
        //converter.setNamePrefix("Sys");
        //converter.setNameSuffix("Impl");

        //properties: { appendPackage: "service.impl", namePrefix: "Sys", nameSuffix: "Impl"}

        Path basePath = new Path("/");
        String basePackage = "com.uh";

        String className = converter.convertToType(new Path("/system/mapper/SysConfigMapper"), basePath, basePackage);
        assertEquals("com.uh.system.mapper.SysConfigMapper", className);

        Path path = converter.converToPath(className, basePath, basePackage);
        assertEquals("/system/mapper/SysConfigMapper", path.toString());


    }
}
